package com.woniuxy.background.service.impl;

import com.woniuxy.background.dao.GoodsMapper;
import com.woniuxy.background.dao.GoodsTypeMapper;
import com.woniuxy.background.pojo.Goods;
import com.woniuxy.background.pojo.GoodsType;
import com.woniuxy.background.service.GoodsTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsTypeServiceImpl implements GoodsTypeService {
    @Autowired
    private GoodsTypeMapper goodsTypeMapper;

    @Autowired
    private GoodsMapper goodsMapper;

    @Override
    public int deleteByPrimaryKey(Integer goodsTypeId) {
        List<Goods> goods = goodsMapper.selectGoodsByGT(goodsTypeId);
        for (Goods g : goods){
            goodsMapper.deleteByPrimaryKey(g.getGoodsId());
        }
        return goodsTypeMapper.deleteByPrimaryKey(goodsTypeId);
    }

    @Override
    public int insert(GoodsType record) {
        return goodsTypeMapper.insert(record);
    }

    @Override
    public int insertSelective(GoodsType record) {
        return goodsTypeMapper.insertSelective(record);
    }

    @Override
    public GoodsType selectByPrimaryKey(Integer goodsTypeId) {
        return goodsTypeMapper.selectByPrimaryKey(goodsTypeId);
    }

    @Override
    public int updateByPrimaryKeySelective(GoodsType record) {
        return goodsTypeMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(GoodsType record) {
        return goodsTypeMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<GoodsType> selectAll() {
        return goodsTypeMapper.selectAll();
    }
}
